package com.fxsh168.server.fragments;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import com.fxsh168.server.interfaces.Constant;
import com.fxsh168.server.R;
import com.fxsh168.server.adapters.OrderAdapter;

import java.util.ArrayList;
import java.util.List;

public class MyOrderFragment extends Fragment {

    private TabLayout tabLayout;
    private ViewPager mOrderViewPager;
    private List<Fragment> orderFragmentLists;
    private OrderAdapter mArderAdapter;
    private OrderAll mOrderAll;
    private Ordering mOrdering;
    private Ordered mOrdered;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.activity_my_order, container, false);
        tabLayout = (TabLayout) view.findViewById(R.id.tabLayout);
        tabLayout.setTabMode(TabLayout.MODE_FIXED);

        mOrderViewPager = (ViewPager) view.findViewById(R.id.orderViewPager);
        orderFragmentLists = new ArrayList<>();

        mOrderAll = new OrderAll();
        orderFragmentLists.add(mOrderAll);
        mOrdering = new Ordering();
        orderFragmentLists.add(mOrdering);
        mOrdered = new Ordered();
        orderFragmentLists.add(mOrdered);


        tabLayout.addTab(tabLayout.newTab().setText(Constant.tabs[0]));
        tabLayout.addTab(tabLayout.newTab().setText(Constant.tabs[1]));
        tabLayout.addTab(tabLayout.newTab().setText(Constant.tabs[2]));

        TabLayout.Tab tab1 = tabLayout.getTabAt(0).setText(Constant.tabs[0]);
        TabLayout.Tab tab2 = tabLayout.getTabAt(1).setText(Constant.tabs[1]);
        TabLayout.Tab tab3 = tabLayout.getTabAt(2).setText(Constant.tabs[2]);

        mOrderViewPager.setAdapter(new OrderAdapter(getFragmentManager(), orderFragmentLists, Constant.tabs));
        tabLayout.setupWithViewPager(mOrderViewPager);
        return view;
    }
}
